package cn.jiahua.hospital.service.impl;

import cn.jiahua.hospital.mapper.HospitalTypeMapper;
import cn.jiahua.hospital.pojo.HospitalType;
import cn.jiahua.hospital.service.HospitalTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.ArrayList;
import java.util.HashMap;

import cn.jiahua.hospital.dto.Page;
import cn.jiahua.hospital.constants.Constants;

@Service
public class HospitalTypeServiceImpl implements HospitalTypeService {

    @Autowired
    private HospitalTypeMapper hospitalTypeMapper;

    @Override
    public HospitalType getHospitalTypeById(Integer id) {
        return hospitalTypeMapper.getHospitalTypeById(id);
    }

    @Override
    public List<HospitalType> getHospitalTypeListByMap(Map<String, Object> param) {
        return hospitalTypeMapper.getHospitalTypeListByMap(param);
    }

    @Override
    public Integer getHospitalTypeCountByMap(Map<String, Object> param) {
        return hospitalTypeMapper.getHospitalTypeCountByMap(param);
    }

    @Override
    public Integer qdtxAddHospitalType(HospitalType hospitalType) {
        return hospitalTypeMapper.insertHospitalType(hospitalType);
    }

    @Override
    public Integer qdtxModifyHospitalType(HospitalType hospitalType) {
        return hospitalTypeMapper.updateHospitalType(hospitalType);
    }

    @Override
    public Integer qdtxDeleteHospitalTypeById(Integer id) {
        return hospitalTypeMapper.deleteHospitalTypeById(id);
    }

    @Override
    public Integer qdtxBatchDeleteHospitalType(String ids) {
        Map<String, List<String>> param = new HashMap<String, List<String>>();
        String[] paramArrays = ids.split(",");
        List<String> idList = new ArrayList<String>();
        for (String temp : paramArrays) {
            idList.add(temp);
        }
        param.put("ids", idList);
        return hospitalTypeMapper.batchDeleteHospitalType(param);
    }

    @Override
    public Page<HospitalType> queryHospitalTypePageByMap(Map<String, Object> param, Integer pageNo, Integer pageSize) {
        Integer total = hospitalTypeMapper.getHospitalTypeCountByMap(param);
        pageNo = pageNo == null ? Constants.DEFAULT_PAGE_NO : pageNo;
        pageSize = pageSize == null ? Constants.DEFAULT_PAGE_SIZE : pageSize;
        Page page = new Page(pageNo, pageSize, total);
        param.put("beginPos", page.getBeginPos());
        param.put("pageSize", page.getPageSize());
        List<HospitalType> hospitalTypeList = hospitalTypeMapper.getHospitalTypeListByMap(param);
        page.setList(hospitalTypeList);
        return page;
    }
}